<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <include file="Public/meta" />
</head>
<body>

<div class="info-center">
    <div class="page-header">
        <div class="pull-left">
            <h4>菜单列表</h4>
        </div>
        <a href="javascript:;" onclick="add()" class="btn btn-primary pull-right margin-top">添加一级菜单</a>
    </div>
    <div class="clearfix"></div>
    <div class="table-margin">
        <table class="table table-hover table-header" id="list-table">
            <thead>
            <tr>
                <td>菜单名称</td>
                <td>链接</td>
                <td>排序</td>
                <td class="w10">操作</td>
            </tr>
            </thead>
            <tbody>
            <foreach name="data" item="vo">
                <tr>
                    <td>
                        <if condition="$vo['parent'] eq 0">
                            {$vo['title']}
                            <else/>
                            &emsp;├─  {$vo['title']}
                        </if>
                    </td>
                    <td>{$vo['url']}</td>
                    <td>
                        <input type="text"
                               onchange="updateSort('Nav','id','{$vo.id}','order',this)"
                               onkeyup="this.value=this.value.replace(/[^\d]/g,'')"
                               onpaste="this.value=this.value.replace(/[^\d]/g,'')"
                               size="4"
                               value="{$vo.order}"
                               class="form-control"
                               style="width:80px"/>
                    </td>
                    <td>
                        <if condition="$vo['parent'] eq 0">
                            <a href="javascript:;"
                               navid="{$vo['id']}"
                               navname="{$vo['title']}"
                               onclick="add_child(this)">
                                添加子菜单
                            </a>
                            <span class="text-explode">|</span>
                        </if>
                        <a href="javascript:;"
                           navid="{$vo['id']}"
                           navname="{$vo['title']}"
                           navurl="{$vo['url']}"
                           onclick="edit(this)">
                            编辑
                        </a>
                        <span class="text-explode">|</span>
                        <a href="javascript:if(confirm('确定删除？')) location ='{:U('HomeNav/delete',array('id'=>$vo['id']))}'" >删除</a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </div>
</div>

<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"> 添加菜单</h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-horizontal" action="{:U('HomeNav/add')}" method="post">
                    <input type="hidden" name="pid" value="0">
                    <table class="table table-hover contact-template-form">
                        <tbody><tr>
                            <td width="20%" align="right">菜单名：</td>
                            <td>
                                <input class="form-control w-300" type="text" name="name">
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="right">链接：</td>
                            <td>
                                <input class="form-control w-300" type="text" name="url">
                                一级菜单：模块/控制器 如：HomeNav
                                <br/>
                                二级菜单：模块/控制器/方法 如：HomeNav/index
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-primary" type="submit" value="添加">
                            </td>
                        </tr>
                        </tbody></table>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"> 修改菜单</h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-horizontal" action="{:U('HomeNav/edit')}" method="post">
                    <input type="hidden" name="id">
                    <table class="table table-hover contact-template-form">
                        <tbody><tr>
                            <td width="20%" align="right">菜单名：</td>
                            <td>
                                <input class="form-control w-300" type="text" name="name">
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="right">链接：</td>
                            <td>
                                <input class="form-control w-300" type="text" name="url">
                                一级菜单：模块/控制器 如：HomeNav
                                <br/>
                                二级菜单：模块/控制器/方法 如：HomeNav/index
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-primary" type="submit" value="修改">
                            </td>
                        </tr>
                        </tbody></table>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__ADMIN_JS__/common.js"></script>
<script>
    // 添加菜单
    function add(){
        $("input[name='name'],input[name='url']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var navId=$(obj).attr('navId');
        $("input[name='pid']").val(navId);
        $("input[name='name']").val('');
        $("input[name='url']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var navId=$(obj).attr('navId');
        var navName=$(obj).attr('navName');
        var navUrl=$(obj).attr('navurl');
        $("input[name='id']").val(navId);
        $("input[name='name']").val(navName);
        $("input[name='url']").val(navUrl);
        $('#bjy-edit').modal('show');
    }

</script>

</body>
</html>